package com.example.gok_mall.reponseData;
//封装的实体类响应数据

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 自定义响应结果集
 * */
@Data
@AllArgsConstructor//实现有参构造
@NoArgsConstructor//无参构造

public class ResultData<T> {
    private String code;
    private String msg;
    private T data;//private T 泛型

    @JsonIgnore
    //使之不再Json序列化的结果当中
    public boolean isSuccess(){
        return this.code==ResponseCode.SUCCESS.getCode();
    }

    public static ResultData success(){
        return new ResultData(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMage(),"null");
    }
    public static ResultData success(String msg){
        return new ResultData(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMage(),  "null");
    }
    public static ResultData fail(String code, String mage){
        return new ResultData(ResponseCode.FAIL.getCode(),ResponseCode.FAIL.getMage(),  "null");
    }
    public static ResultData fail(String msg){
        return new ResultData(ResponseCode.FAIL.getCode(),msg, "null");
    }

    public static ResultData createData(Object data) {
        return new ResultData(ResponseCode.SUCCESS.getCode(), "null",data);
    }

}


